package com.android.pdd.baseapp.hook;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ViewCreater {
    public static class LinearLayoutBuilder {
        public static LinearLayoutBuilder newInstance(Context context) {
            return new LinearLayoutBuilder(context);
        }

        private LinearLayout linearLayout;
        private ViewGroup.MarginLayoutParams layoutParams;

        public LinearLayout build() {
            linearLayout.setLayoutParams(layoutParams);
            return linearLayout;
        }

        public LinearLayoutBuilder setMargin(int left, int top, int right, int bottom) {
            layoutParams.leftMargin = left;
            layoutParams.topMargin = top;
            layoutParams.rightMargin = right;
            layoutParams.bottomMargin = bottom;
            return this;
        }

        public LinearLayoutBuilder setPadding(int left, int top, int right, int bottom) {
            linearLayout.setPadding(left, top, right, bottom);
            return this;
        }

        public LinearLayoutBuilder(Context context) {
            this.linearLayout = new LinearLayout(context);
            linearLayout.setOrientation(LinearLayout.VERTICAL);
            layoutParams = new ViewGroup.MarginLayoutParams(ViewGroup.MarginLayoutParams.WRAP_CONTENT, ViewGroup.MarginLayoutParams.WRAP_CONTENT);
        }

        public LinearLayoutBuilder setOrientationVertical() {
            linearLayout.setOrientation(LinearLayout.VERTICAL);
            return this;
        }

        public LinearLayoutBuilder setOrientationHorizontal() {
            linearLayout.setOrientation(LinearLayout.HORIZONTAL);
            return this;
        }

        public LinearLayoutBuilder setWidth(int width) {
            layoutParams.width = width;
            return this;
        }

        public LinearLayoutBuilder setHeight(int height) {
            layoutParams.height = height;
            return this;
        }

        public LinearLayoutBuilder setWidthMatch() {
            layoutParams.width = ViewGroup.MarginLayoutParams.MATCH_PARENT;
            return this;
        }

        public LinearLayoutBuilder setHeightMatch() {
            layoutParams.height = ViewGroup.MarginLayoutParams.MATCH_PARENT;
            return this;
        }
    }

    public static class TextViewBuilder {
        private TextView textView;
        private ViewGroup.MarginLayoutParams layoutParams;

        public static TextViewBuilder newInstance(Context context){
            return new TextViewBuilder(context);
        }
        public TextViewBuilder setSelector(int normalColor, int pressColor, int radius) {
            SelectorUtil.setSelectorFromTextView(textView, normalColor, pressColor, radius);
            return this;
        }

        public TextViewBuilder(Context context) {
            this.textView = new TextView(context);
            layoutParams = new ViewGroup.MarginLayoutParams(ViewGroup.MarginLayoutParams.WRAP_CONTENT, ViewGroup.MarginLayoutParams.WRAP_CONTENT);
        }

        public TextViewBuilder setGravity(int gravity) {
            textView.setGravity(gravity);
            return this;
        }

        public TextViewBuilder setText(String text) {
            textView.setText(text);
            return this;
        }

        public TextViewBuilder setTextColor(int color) {
            textView.setTextColor(color);
            return this;
        }

        public TextViewBuilder setTextSize(float size) {
            textView.setTextSize(size);
            return this;
        }

        public TextViewBuilder setOnClickListener(View.OnClickListener clickListener) {
            textView.setOnClickListener(clickListener);
            return this;
        }

        public TextViewBuilder setWidth(int width) {
            layoutParams.width = width;
            return this;
        }

        public TextViewBuilder setHeight(int height) {
            layoutParams.height = height;
            return this;
        }

        public TextViewBuilder setWidthMatch() {
            layoutParams.width = ViewGroup.MarginLayoutParams.MATCH_PARENT;
            return this;
        }

        public TextViewBuilder setHeightMatch() {
            layoutParams.height = ViewGroup.MarginLayoutParams.MATCH_PARENT;
            return this;
        }

        public TextViewBuilder setMargin(int left, int top, int right, int bottom) {
            layoutParams.leftMargin = left;
            layoutParams.topMargin = top;
            layoutParams.rightMargin = right;
            layoutParams.bottomMargin = bottom;
            return this;
        }

        public TextViewBuilder setPadding(int left, int top, int right, int bottom) {
            textView.setPadding(left, top, right, bottom);
            return this;
        }

        public TextView build() {
            textView.setLayoutParams(layoutParams);
            return textView;
        }

        public TextViewBuilder setLayoutWeight(int weight) {
            layoutParams = new LinearLayout.LayoutParams(layoutParams);
            ((LinearLayout.LayoutParams) layoutParams).weight = weight;
            return this;
        }
    }
}
